/**
 * @file main.c
 * @author yuchsh
 * @brief 主函数
 * @version 0.1
 * @date 2025-05-10
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs_flash.h"
#include <stdio.h>
#include "led.h"
#include "key.h"


/**
 * @brief       程序入口
 * @param       无
 * @retval      无
 */
void app_main(void)
{
    esp_err_t ret;
    uint8_t key = 0;
    
    ret = nvs_flash_init();     /* 初始化NVS */

    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
    {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ESP_ERROR_CHECK(nvs_flash_init());
    }

    led_init();                 /* 初始化LED */
    key_init();                 /* 初始化KEY */

    while(1)
    {
        key = key_scan(1); // 1 支持长按 0 不支持长按

        if (key) // 判断有没有键按下
        {
            if (key == BOOT_PRES) // 判断按下的是哪个键
            {
                // LED0_TOGGLE();
                LED0(1);
            }
        } else {
            LED0(0);
        }

        vTaskDelay(pdMS_TO_TICKS(10));
    }
}
